<template>
	<uni-popup type="bottom" ref="popup" :is-mask-click="true" @close="close" @maskClick="close">
		<view class="balance">
			<view class="balance-top">
				<goods-price :price="balance" txt=" "></goods-price>
				<Text class="balance-top-txt">我的余额</Text>
			</view>
			<view class="flex balance-item">
				<view class="txt">
					余额支付
				</view>
				<view class="select" @click="toggleBalanceCheck">
					<image v-show="!balancePay" class="check-icon" src="../../static/images/check.svg" mode=""></image>
					<image v-show="balancePay" class="check-icon" src="../../static/images/checked.svg" mode=""></image>
				</view>
			</view>
			<view class="balance-btn" @click="pay">
				下一步
			</view>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		data() {
			return {
				balancePay: false,
			}
		},
		props: {
			value: {
				type: Boolean,
				default: false
			},
			balance: {
				type: Number,
				default: 0
			}
		},
		watch: {
			value(nVal, oVal) {
				if (nVal) this.$refs.popup.open();
			}
		},
		methods: {
			close() {
				this.$refs.popup.close();
				this.$emit('closeBalance', false)
			},
			toggleBalanceCheck() {
				this.balancePay = !this.balancePay;
			},
			pay() {
				this.close();
				this.$emit('pay', this.balancePay)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.flex {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
	}
	.balance {
		width: 100%;
		background-color: #fff;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		position: absolute;
		bottom: -100rpx;
		left: 0;
		z-index: 99;
		padding: 40rpx 40rpx;
		padding-bottom: 140rpx;
		box-sizing: border-box;
		overflow: hidden;
		.balance-top{
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 20rpx 0;
			&-txt{
				font-size: 24rpx;
				color: #999;
				margin-top: 20rpx;
			}
		}
		.balance-item {
			height: 72rpx;
		}
		.txt {
			color: #2e2e2e;
			font-size: 28rpx;
			height: 72rpx;
			line-height: 72rpx;
		}
		.select {
			width: 40rpx;
			height: 40rpx;
		}
		.check-icon {
			width: 40rpx;
			height: 40rpx;
		}
		.balance-btn {
			height: 72rpx;
			width: 100%;
			line-height: 72rpx;
			box-sizing: border-box;
			border-radius: 36rpx;
			background: linear-gradient(113deg, #FADF5D 18%, #F7D35D 81%);
			text-align: center;
			color: #30240A;
			font-size: 28rpx;
			margin-top: 30rpx;
		}
	}
</style>